package com.pomelo.tiku.activities

import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.blankj.utilcode.util.LogUtils
import com.pomelo.tiku.R
import com.pomelo.tiku.adapters.AnswerQuesionAdapter
import com.pomelo.tiku.views.CommonToast
import kotlinx.android.synthetic.main.activity_answer_question.*
import kotlinx.android.synthetic.main.fragment_home.view.*

class AnswerQuestionActivity : BaseActivity() {
    private var list_question: ArrayList<String>? = null
    private var questionAdapter: AnswerQuesionAdapter? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_answer_question)
        getDataFromHome()
        initVacationRv()
    }

    private fun getDataFromHome() {
        val intent = intent
        val budle = intent.extras
        val questionPattern = budle!!.getString("question_pattern")
        CommonToast.show(this@AnswerQuestionActivity,"当前${questionPattern}")
    }
    private fun initVacationRv() {
        list_question = ArrayList()
        list_question!!.add("第1题：Java定义静态变量是什么修饰符？")
        list_question!!.add("第2题：ArrayList和Vector的区别,HashMap和Hashtable的区别？")
        list_question!!.add("第3题：Java定义静态变量是什么修饰符？")
        list_question!!.add("第4题：Java定义静态变量是什么修饰符？")
        list_question!!.add("第5题：Java定义静态变量是什么修饰符？")
        list_question!!.add("第6题：同步性:Vector是线程安全的，也就是说是同步的，而ArrayList是线程序不安全的，不是同步的\n" + "\n" +
                "二.数据增长:当需要增长时,Vector默认增长为原来一培，而ArrayList却是原来的一半\n" +
                "\n" +
                "就HashMap与HashTable主要从三方面来说")
        questionAdapter = AnswerQuesionAdapter(this,list_question)

        val layoutManager: LinearLayoutManager =
            object : LinearLayoutManager(this, HORIZONTAL, false) {
                override fun canScrollHorizontally(): Boolean {
                    return false
                }
            }
        rv_answer_question.layoutManager = layoutManager
        rv_answer_question.adapter = questionAdapter
        questionAdapter!!.setOnItemViewClicklistener(object : AnswerQuesionAdapter.OnItemViewClick {
            override fun onSubmitClick(position: Int) {
               if(position < list_question!!.size -1) {
                   rv_answer_question.scrollToPosition(position + 1)
               } else {
                   CommonToast.show(this@AnswerQuestionActivity,"你已完成答题")
               }
            }

            override fun onResolveClick(position: Int) {
                CommonToast.show(this@AnswerQuestionActivity,"点击了解析")
            }

            override fun onPraiseClick(position: Int) {
                CommonToast.show(this@AnswerQuestionActivity,"点击了点赞")
            }

            override fun onCollectClick(position: Int) {
                CommonToast.show(this@AnswerQuestionActivity,"点击了收藏")
            }

            override fun onMessageClick(position: Int) {
                CommonToast.show(this@AnswerQuestionActivity,"点击了信息")
            }

        })

    }
}